/**
 * BrandBigData.com Inc.
 * Copyright (c) 2018 All Rights Reserved.
 */
package com.qibao.toolkit.generator;

import com.qibao.toolkit.util.MutilTenantIdGeneratorUtils;

/**
 * @author HaoBin
 * @version $Id: IdWorkerFactory.java, v0.1 2018/3/19 16:27 HaoBin
 */
public class IdWorkerFactory {

    private static MutilTenantIdGeneratorUtils worker;

    private static Long workerId = 1L;

    private static int tenantMask = 0X3FFF;

    public static Long getId(Long tenantId) {
        if (worker == null) {
            worker = new MutilTenantIdGeneratorUtils(workerId);
        }
        return worker.nextId(tenantId);

    }

    public static Long getTenantId(Long ratingRequestId) {
        Long tenantId = ratingRequestId & tenantMask;
        return tenantId;
    }

    public static void setWorkerId(Long machineId) {
        workerId = machineId;
    }
}